package com.huawang.mdesign.model.service.controller;

import com.huawang.business.util.ValidateDataUtil;
import com.huawang.mdesign.model.service.inter.InformationFlowService;
import com.huawang.mdesign.model.service.vo.BaseResponse;
import com.huawang.mdesign.model.service.vo.ExchangeInformationFlowVo;
import com.huawang.mdesign.model.service.vo.ExchangeSendingReceivingVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "信息流")
@RestController
@RequestMapping("/informationFlow")
public class InformationFlowController {
    @Autowired
    private InformationFlowService informationFlowService;

    @Operation(summary = "根据关系，获取信息流两端的可用元素")
    @GetMapping("/querySendingAndReceiving")
    public BaseResponse<ExchangeSendingReceivingVo> querySendingAndReceiving(@RequestParam final String projectId,
                                                                             @RequestParam final String exchangeTypeId,
                                                                             @RequestParam(required = false) final String relationId) {
        ValidateDataUtil.isNotEmpty(projectId);
        ValidateDataUtil.isNotEmpty(exchangeTypeId);
        return BaseResponse.success(informationFlowService.querySendingAndReceiving(projectId, exchangeTypeId, relationId));
    }

    @Operation(summary = "根据关系，获取信息流列表")
    @GetMapping("/queryInformationFlowByRelation")
    public BaseResponse<List<ExchangeInformationFlowVo>> queryInformationFlowByRelation(@RequestParam final String projectId,
                                                                                        @RequestParam final String exchangeTypeId,
                                                                                        @RequestParam(required = false) final String exchangeKind,
                                                                                        @RequestParam final String relationId) {
        ValidateDataUtil.isNotEmpty(projectId);
        ValidateDataUtil.isNotEmpty(exchangeTypeId);
        ValidateDataUtil.isNotEmpty(relationId);
        return BaseResponse.success(informationFlowService.queryInformationFlowByRelation(projectId, exchangeTypeId, exchangeKind, relationId));
    }

    @Operation(summary = "活动边是否能关联信息流")
    @GetMapping("/canActivityEdgeAttachInformationFlow")
    public BaseResponse<Boolean> canActivityEdgeAttachInformationFlow(@RequestParam final String projectId,
                                                                      @RequestParam final String relationId) {
        return BaseResponse.success(informationFlowService.canActivityEdgeAttachInformationFlow(projectId, relationId));
    }
}